/* eslint-disable */
export class NumberFormat {
  static formatNumber(num) {
    if (num == null) {
      return '';
    }
    const parts = num.toString().split('.');
    parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, ',');
    return parts.join('.');
  }
  // 格式化人民币
  static formatMoney(s) {
    if (s === 0) {
      return '￥0.00';
    }
    if (!s) {
      return 'invalid value';
    }
    if (/[^0-9\.]/.test(s)) {
      return 'invalid value';
    }
    if (s === 0) {
      return 0;
    } else {
      s = s + '';
      s = s.replace(/^(\d*)$/, '$1.');
      s = (s + '00').replace(/(\d*\.\d\d)\d*/, '$1');
      s = s.replace('.', ',');
      const re = /(\d)(\d{3},)/;
      while (re.test(s)) {
        s = s.replace(re, '$1,$2');
      }
      s = s.replace(/,(\d\d)$/, '.$1');
      return '￥' + s.replace(/^\./, '0.');
    }
  }
}
